package Managers;

/**
* Created by Oliver Mrazik on 5. 6. 2014.
* author: Oliver Mrazik
* version: 2014-06-05
*/

import Tools.DatabaseException;

/**
* FOR TESTING PURPOSE
*/
public class Main {

    public static void main(String args[]) throws Exception {

        try {
            CategoryManagerImpl categoryManager = new CategoryManagerImpl("db/videolib-categories", "admin", "password1234");
            LibraryManagerImpl libraryManager = new LibraryManagerImpl("db/videolib-mediums", "db/videolib-categories", "admin", "password1234");
            MediumManagerImpl mediumManager = new MediumManagerImpl("db/videolib-mediums", "admin", "password1234");
//
//            Medium[] mediums = new Medium[5];
//            Category[] categories = new Category[3];
//
//            mediums[0] = new Medium();
//            mediums[0].setLabel("Dovolenka-Tunisko");
//            mediums[0].setType("Blu-Ray");
//            mediums[0].setMovies(Arrays.asList("fotky", "videa"));
//
//            mediums[1] = new Medium();
//            mediums[1].setLabel("Dovolenka-Taliansko");
//            mediums[1].setType("DVD");
//            mediums[1].setMovies(Arrays.asList("fotky1", "fotky2"));
//
//            mediums[2] = new Medium();
//            mediums[2].setLabel("Oslava-10.6.2014");
//            mediums[2].setType("CD");
//            mediums[2].setMovies(Arrays.asList("fotky"));
//
//            mediums[3] = new Medium();
//            mediums[3].setLabel("Svatba-dcera");
//            mediums[3].setType("Blu-Ray");
//            mediums[3].setMovies(Arrays.asList("videa1", "videa2", "fotky"));
//
//            mediums[4] = new Medium();
//            mediums[4].setLabel("Blbosti");
//            mediums[4].setType("DVD");
//            mediums[4].setMovies(Arrays.asList("blbosti1"));
//
//            categories[0] = new Category();
//            categories[0].setName("Oslavy");
//
//            categories[1] = new Category();
//            categories[1].setName("Dovolenky");
//
//            categories[2] = new Category();
//            categories[2].setName("Ostatne");
//
//            //create mediums
//            for (int i = 0; i < mediums.length; i++) {
//                mediumManager.createMedium(mediums[i]);
//                //System.out.println(mediums[i].getId());
//            }
//
//            //create categories
//            for (int i = 0; i < categories.length; i++) {
//                categoryManager.createCategory(categories[i]);
//                //System.out.println(categories[i].getId());
//            }
//
//            //insert mediums into categories
//            libraryManager.insertMediumIntoCategory(mediumManager.getMediumByLabel("Dovolenka-Tunisko"), categoryManager.getCategoryByName("Dovolenky"));
//            libraryManager.insertMediumIntoCategory(mediumManager.getMediumByLabel("Dovolenka-Taliansko"), categoryManager.getCategoryByName("Dovolenky"));
//            libraryManager.insertMediumIntoCategory(mediumManager.getMediumByLabel("Oslava-10.6.2014"), categoryManager.getCategoryByName("Oslavy"));
//            libraryManager.insertMediumIntoCategory(mediumManager.getMediumByLabel("Svatba-dcera"), categoryManager.getCategoryByName("Oslavy"));
//            libraryManager.insertMediumIntoCategory(mediumManager.getMediumByLabel("Blbosti"), categoryManager.getCategoryByName("Ostatne"));
//
//            //test output of method - switched off
//            libraryManager.getCategoryWithMediumsAsXMLDocument(categoryManager.getCategoryByName("Oslavy").getId());
//
//            //test output of method - switched off
//            libraryManager.getDatabaseContentAsXMLDocument();
//
//            // remove mediums from categories
//            libraryManager.removeMediumFromCategory(mediumManager.getMediumByLabel("Dovolenka-Tunisko"), categoryManager.getCategoryByName("Dovolenky"));
//            libraryManager.removeMediumFromCategory(mediumManager.getMediumByLabel("Dovolenka-Taliansko"), categoryManager.getCategoryByName("Dovolenky"));
//            libraryManager.removeMediumFromCategory(mediumManager.getMediumByLabel("Oslava-10.6.2014"), categoryManager.getCategoryByName("Oslavy"));
//            libraryManager.removeMediumFromCategory(mediumManager.getMediumByLabel("Svatba-dcera"), categoryManager.getCategoryByName("Oslavy"));
//            libraryManager.removeMediumFromCategory(mediumManager.getMediumByLabel("Blbosti"), categoryManager.getCategoryByName("Ostatne"));
//
//            //========================================================================================================//
//            //test delete medium and category
//            Medium testMed = new Medium();
//            testMed.setLabel("Test update");
//            testMed.setType("DVD");
//            testMed.setMovies(Arrays.asList("film1", "film2"));
//
//            Category testCat = new Category();
//            testCat.setName("Test update");
//
//            mediumManager.createMedium(testMed);
//            categoryManager.createCategory(testCat);
//
//            testMed.setLabel("Test delete");
//            testMed.setType("CD");
//
//            mediumManager.updateMedium(testMed);
//            categoryManager.renameCategory(testCat, "Test delete");
//
//            mediumManager.deleteMedium(testMed);
//            categoryManager.deleteCategory(testCat);
//            //========================================================================================================//
//
//            //remove mediums
//            for (Medium med : mediums) {
//                mediumManager.deleteMedium(med);
//            }
//
//            //remove categories
//            for (Category cat : categories) {
//                categoryManager.deleteCategory(cat);
//            }

            //mediumManager.getAllMediumsAsXMLDocument();

//            Category cat = categoryManager.getCategoryByName("Seriály_-_originál");
//            for (String id : cat.getMediums()) {
//                System.out.println(id);
//            }


//            XMLParser parser = new XMLParser(categoryManager, mediumManager, libraryManager);
//            parser.importFromODF("C:\\Users\\Natrezim\\IdeaProjects\\Testovaci.ods");
//            parser.exportToODF("C:\\Users\\Natrezim\\IdeaProjects\\Export.ods", categoryManager.listAllCategories());


//            System.out.println(libraryManager.getDatabaseContentAsXMLDocument(true));
            System.out.println(libraryManager.getAllMediumsAsXMLDocument());
        } catch (DatabaseException ex) {
            ex.printStackTrace();
        }
    }
}

